

<!doctype html>

<html lang="en" data-content_root="../../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>skidl.skidlbaseobj &#8212; SKiDL 2.2.0 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
    <link rel="stylesheet" type="text/css" href="../../_static/bizstyle.css?v=a66e137f" />
    
    <script src="../../_static/documentation_options.js?v=b21de401"></script>
    <script src="../../_static/doctools.js?v=9bcbadda"></script>
    <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../../_static/bizstyle.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <!--[if lt IE 9]>
    <script src="_static/css3-mediaqueries.js"></script>
    <![endif]-->
  </head><body>
    <h1 id="site-title"><a href="../../../../"><img src="../../../../images/slim_banner.png" width="100%"></a></h1>
    
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SKiDL 2.2.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">skidl.skidlbaseobj</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for skidl.skidlbaseobj</h1><div class="highlight"><pre>
<span></span><span class="c1"># -*- coding: utf-8 -*-</span>

<span class="c1"># The MIT License (MIT) - Copyright (c) Dave Vandenbout.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Base object for Circuit, Interface, Part, Net, Bus, Pin objects.</span>

<span class="sd">This module provides the foundation class SkidlBaseObject that all major SKiDL objects</span>
<span class="sd">inherit from. It implements common functionality such as ERC checking, attribute handling,</span>
<span class="sd">and object copying.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">inspect</span>
<span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">string</span>
<span class="kn">import</span> <span class="nn">os.path</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">namedtuple</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">deepcopy</span>

<span class="kn">from</span> <span class="nn">.alias</span> <span class="kn">import</span> <span class="n">Alias</span>
<span class="kn">from</span> <span class="nn">.note</span> <span class="kn">import</span> <span class="n">Note</span>
<span class="kn">from</span> <span class="nn">.utilities</span> <span class="kn">import</span> <span class="n">export_to_all</span>


<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;OK&quot;</span><span class="p">,</span> <span class="s2">&quot;WARNING&quot;</span><span class="p">,</span> <span class="s2">&quot;ERROR&quot;</span><span class="p">]</span>

<span class="n">OK</span><span class="p">,</span> <span class="n">WARNING</span><span class="p">,</span> <span class="n">ERROR</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">))</span>


<div class="viewcode-block" id="SkidlBaseObject">
<a class="viewcode-back" href="../../rst_output/skidl.skidlbaseobj.html#skidl.skidlbaseobj.SkidlBaseObject">[docs]</a>
<span class="nd">@export_to_all</span>
<span class="k">class</span> <span class="nc">SkidlBaseObject</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Base class for all SKiDL objects.</span>

<span class="sd">    This class provides common functionality for all SKiDL objects such as</span>
<span class="sd">    attribute handling, ERC checking, and object copying. It also manages</span>
<span class="sd">    object names, aliases, and notes.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># These are fallback lists so every object will have them to reference.</span>
    <span class="n">erc_list</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">erc_assertion_list</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Initialize a new SkidlBaseObject with empty fields dictionary.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fields</span> <span class="o">=</span> <span class="p">{}</span>

    <span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Retrieve an attribute from the fields dictionary.</span>

<span class="sd">        Args:</span>
<span class="sd">            key: The attribute name to retrieve.</span>

<span class="sd">        Returns:</span>
<span class="sd">            The value of the attribute.</span>

<span class="sd">        Raises:</span>
<span class="sd">            AttributeError: If the attribute doesn&#39;t exist.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># Don&#39;t use super()!! It leads to long run times on Python 2.7.</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__getattribute__</span><span class="p">(</span><span class="s2">&quot;fields&quot;</span><span class="p">)[</span><span class="n">key</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">AttributeError</span>

    <span class="k">def</span> <span class="fm">__setattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set an attribute either directly or in the fields dictionary.</span>

<span class="sd">        If the key is &#39;fields&#39; or doesn&#39;t exist in fields, sets it directly,</span>
<span class="sd">        otherwise updates the fields dictionary.</span>

<span class="sd">        Args:</span>
<span class="sd">            key: The attribute name to set.</span>
<span class="sd">            value: The value to assign to the attribute.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="s2">&quot;fields&quot;</span> <span class="ow">or</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">:</span>
            <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__setattr__</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>

<div class="viewcode-block" id="SkidlBaseObject.copy">
<a class="viewcode-back" href="../../rst_output/skidl.skidlbaseobj.html#skidl.skidlbaseobj.SkidlBaseObject.copy">[docs]</a>
    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Create a deep copy of this object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A new SkidlBaseObject with copies of this object&#39;s fields, aliases, and notes.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cpy</span> <span class="o">=</span> <span class="n">SkidlBaseObject</span><span class="p">()</span>
        <span class="n">cpy</span><span class="o">.</span><span class="n">fields</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fields</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">cpy</span><span class="o">.</span><span class="n">aliases</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">aliases</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">cpy</span><span class="o">.</span><span class="n">notes</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">notes</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">return</span> <span class="n">cpy</span></div>


<div class="viewcode-block" id="SkidlBaseObject.ERC">
<a class="viewcode-back" href="../../rst_output/skidl.skidlbaseobj.html#skidl.skidlbaseobj.SkidlBaseObject.ERC">[docs]</a>
    <span class="k">def</span> <span class="nf">ERC</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Run Electrical Rules Check on this object.</span>

<span class="sd">        This method runs all ERC functions and evaluates all ERC assertions</span>
<span class="sd">        assigned to the object.</span>

<span class="sd">        Args:</span>
<span class="sd">            *args: Arguments to pass to ERC functions.</span>
<span class="sd">            **kwargs: Keyword arguments to pass to ERC functions.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Run ERC functions.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_exec_erc_functions</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="c1"># Run ERC assertions.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_eval_erc_assertions</span><span class="p">()</span></div>


<div class="viewcode-block" id="SkidlBaseObject.add_erc_function">
<a class="viewcode-back" href="../../rst_output/skidl.skidlbaseobj.html#skidl.skidlbaseobj.SkidlBaseObject.add_erc_function">[docs]</a>
    <span class="k">def</span> <span class="nf">add_erc_function</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add an ERC function to this object or its class.</span>

<span class="sd">        Args:</span>
<span class="sd">            func: A function that will be called during ERC checking.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">erc_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">func</span><span class="p">)</span></div>


<div class="viewcode-block" id="SkidlBaseObject.add_erc_assertion">
<a class="viewcode-back" href="../../rst_output/skidl.skidlbaseobj.html#skidl.skidlbaseobj.SkidlBaseObject.add_erc_assertion">[docs]</a>
    <span class="k">def</span> <span class="nf">add_erc_assertion</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">assertion</span><span class="p">,</span> <span class="n">fail_msg</span><span class="o">=</span><span class="s2">&quot;FAILED&quot;</span><span class="p">,</span> <span class="n">severity</span><span class="o">=</span><span class="n">ERROR</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add an ERC assertion to this object or its class.</span>

<span class="sd">        Args:</span>
<span class="sd">            assertion: A string containing a Python expression that should evaluate to True.</span>
<span class="sd">            fail_msg: Message to display if assertion fails.</span>
<span class="sd">            severity: Level of severity (ERROR, WARNING, or OK) if assertion fails.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Tuple for storing assertion code object with its global &amp; local dicts.</span>
        <span class="n">EvalTuple</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span>
            <span class="s2">&quot;EvalTuple&quot;</span><span class="p">,</span>
            <span class="s2">&quot;stmnt fail_msg severity filename lineno function globals locals&quot;</span><span class="p">,</span>
        <span class="p">)</span>

        <span class="n">assertion_frame</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">lineno</span><span class="p">,</span> <span class="n">function</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">inspect</span><span class="o">.</span><span class="n">stack</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">erc_assertion_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
            <span class="n">EvalTuple</span><span class="p">(</span>
                <span class="n">assertion</span><span class="p">,</span>
                <span class="n">fail_msg</span><span class="p">,</span>
                <span class="n">severity</span><span class="p">,</span>
                <span class="n">filename</span><span class="p">,</span>
                <span class="n">lineno</span><span class="p">,</span>
                <span class="n">function</span><span class="p">,</span>
                <span class="n">assertion_frame</span><span class="o">.</span><span class="n">f_globals</span><span class="p">,</span>
                <span class="n">assertion_frame</span><span class="o">.</span><span class="n">f_locals</span><span class="p">,</span>
            <span class="p">)</span>
        <span class="p">)</span></div>


    <span class="k">def</span> <span class="nf">_eval_erc_assertions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Evaluate all ERC assertions for this object.</span>

<span class="sd">        This method evaluates all assertions and logs failures with appropriate</span>
<span class="sd">        severity levels.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">.logger</span> <span class="kn">import</span> <span class="n">active_logger</span>

        <span class="k">def</span> <span class="nf">erc_report</span><span class="p">(</span><span class="n">evtpl</span><span class="p">):</span>
            <span class="n">log_msg</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">evtpl</span><span class="o">.</span><span class="n">stmnt</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="n">evtpl</span><span class="o">.</span><span class="n">fail_msg</span><span class="si">}</span><span class="s2"> in </span><span class="si">{</span><span class="n">evtpl</span><span class="o">.</span><span class="n">filename</span><span class="si">}</span><span class="s2">:</span><span class="si">{</span><span class="n">evtpl</span><span class="o">.</span><span class="n">lineno</span><span class="si">}</span><span class="s2">:</span><span class="si">{</span><span class="n">evtpl</span><span class="o">.</span><span class="n">function</span><span class="si">}</span><span class="s2">.&quot;</span>
            <span class="k">if</span> <span class="n">evtpl</span><span class="o">.</span><span class="n">severity</span> <span class="o">==</span> <span class="n">ERROR</span><span class="p">:</span>
                <span class="n">active_logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">log_msg</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">evtpl</span><span class="o">.</span><span class="n">severity</span> <span class="o">==</span> <span class="n">WARNING</span><span class="p">:</span>
                <span class="n">active_logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="n">log_msg</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">evtpl</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">erc_assertion_list</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">eval</span><span class="p">(</span><span class="n">evtpl</span><span class="o">.</span><span class="n">stmnt</span><span class="p">,</span> <span class="n">evtpl</span><span class="o">.</span><span class="n">globals</span><span class="p">,</span> <span class="n">evtpl</span><span class="o">.</span><span class="n">locals</span><span class="p">)</span> <span class="o">==</span> <span class="kc">False</span><span class="p">:</span>
                <span class="n">erc_report</span><span class="p">(</span><span class="n">evtpl</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_exec_erc_functions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Execute ERC functions on this object.</span>

<span class="sd">        Args:</span>
<span class="sd">            *args: Arbitrary argument list passed to each ERC function.</span>
<span class="sd">            **kwargs: Arbitrary keyword arguments passed to each ERC function.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Execute any instance functions for this particular instance.</span>
        <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">erc_list</span><span class="p">:</span>
            <span class="n">f</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the primary name of this object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            The primary name of this object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_name</span>

    <span class="nd">@name</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nm</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set the primary name of this object and add it to aliases.</span>

<span class="sd">        Args:</span>
<span class="sd">            nm: The new name for this object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>  <span class="c1"># Remove any pre-existing name.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">aliases</span> <span class="o">+=</span> <span class="n">nm</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_name</span> <span class="o">=</span> <span class="n">nm</span>

    <span class="nd">@name</span><span class="o">.</span><span class="n">deleter</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Remove the primary name from this object and its aliases.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">aliases</span><span class="o">.</span><span class="n">discard</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_name</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_name</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">pass</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">tag</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the tag of this object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            The tag of this object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tag</span>

    <span class="nd">@tag</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">tag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tag_</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set the tag of this object.</span>

<span class="sd">        Args:</span>
<span class="sd">            tag_: The new tag for this object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">tag</span>  <span class="c1"># Remove any pre-existing tag.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_tag</span> <span class="o">=</span> <span class="n">tag_</span>

    <span class="nd">@tag</span><span class="o">.</span><span class="n">deleter</span>
    <span class="k">def</span> <span class="nf">tag</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Remove the tag from this object.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tag</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">pass</span>

<div class="viewcode-block" id="SkidlBaseObject.check_tag">
<a class="viewcode-back" href="../../rst_output/skidl.skidlbaseobj.html#skidl.skidlbaseobj.SkidlBaseObject.check_tag">[docs]</a>
    <span class="k">def</span> <span class="nf">check_tag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">create_if_missing</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Check if the tag is set for this object.</span>
<span class="sd">        Warn if the tag is not set.</span>

<span class="sd">        Returns:</span>
<span class="sd">            True if the tag is set, False otherwise.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">skidl.logger</span> <span class="kn">import</span> <span class="n">active_logger</span>

        <span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;tag&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">active_logger</span><span class="o">.</span><span class="n">bare_warning</span><span class="p">(</span>
                <span class="sa">f</span><span class="s2">&quot;Missing tag on </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2"> instantiated at </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">src_line</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span><span class="si">}</span><span class="s2">.&quot;</span>
            <span class="p">)</span>
            <span class="k">if</span> <span class="n">create_if_missing</span><span class="p">:</span>
                <span class="c1"># Create a random tag if it is missing.</span>
                <span class="n">chars</span> <span class="o">=</span> <span class="n">string</span><span class="o">.</span><span class="n">ascii_letters</span> <span class="o">+</span> <span class="n">string</span><span class="o">.</span><span class="n">digits</span> <span class="o">+</span> <span class="s2">&quot;_&quot;</span>
                <span class="n">length</span> <span class="o">=</span> <span class="mi">10</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">tag</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">choices</span><span class="p">(</span><span class="n">chars</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="n">length</span><span class="p">))</span>
                <span class="n">active_logger</span><span class="o">.</span><span class="n">bare_warning</span><span class="p">(</span>
                    <span class="sa">f</span><span class="s2">&quot;Random tag </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">tag</span><span class="si">}</span><span class="s2"> generated for </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s2">.&quot;</span>
                <span class="p">)</span>
            <span class="k">return</span> <span class="kc">False</span></div>


    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">aliases</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the aliases for this object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            An Alias object containing all alternate names for this object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_aliases</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Alias</span><span class="p">([])</span>  <span class="c1"># No aliases, so just return an empty list.</span>

    <span class="nd">@aliases</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">aliases</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name_or_list</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set aliases for this object.</span>

<span class="sd">        Args:</span>
<span class="sd">            name_or_list: A name or list of names to use as aliases.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">name_or_list</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_aliases</span> <span class="o">=</span> <span class="n">Alias</span><span class="p">(</span><span class="n">name_or_list</span><span class="p">)</span>

    <span class="nd">@aliases</span><span class="o">.</span><span class="n">deleter</span>
    <span class="k">def</span> <span class="nf">aliases</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Remove all aliases from this object.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_aliases</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">pass</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">notes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the notes for this object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A Note object containing all notes associated with this object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_notes</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">Note</span><span class="p">([])</span>  <span class="c1"># No notes, so just return empty list.</span>

    <span class="nd">@notes</span><span class="o">.</span><span class="n">setter</span>
    <span class="k">def</span> <span class="nf">notes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text_or_notes</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set notes for this object.</span>

<span class="sd">        Args:</span>
<span class="sd">            text_or_notes: Text string or Note object to associate with this object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">text_or_notes</span><span class="p">:</span>
            <span class="k">return</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_notes</span> <span class="o">=</span> <span class="n">Note</span><span class="p">(</span><span class="n">text_or_notes</span><span class="p">)</span>

    <span class="nd">@notes</span><span class="o">.</span><span class="n">deleter</span>
    <span class="k">def</span> <span class="nf">notes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Remove all notes from this object.&quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_notes</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">pass</span>

<div class="viewcode-block" id="SkidlBaseObject.src_line">
<a class="viewcode-back" href="../../rst_output/skidl.skidlbaseobj.html#skidl.skidlbaseobj.SkidlBaseObject.src_line">[docs]</a>
    <span class="k">def</span> <span class="nf">src_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">track_abs_path</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the file name and line number where the object was instantiated.</span>

<span class="sd">        Args:</span>
<span class="sd">            track_abs_path (bool): If True, use the absolute path of the file.</span>
<span class="sd">                                   If False, use the relative path from the script directory.</span>
<span class="sd">        </span>
<span class="sd">        Returns:</span>
<span class="sd">            str: File name and line number separated by colon.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">file_path</span><span class="p">,</span> <span class="n">file_line</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">skidl_trace</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="k">except</span> <span class="p">(</span><span class="ne">AttributeError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span>
            <span class="c1"># If skidl_trace is not set or empty, return an empty string.</span>
            <span class="k">return</span> <span class="s2">&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">track_abs_path</span><span class="p">:</span>
            <span class="n">file_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">relpath</span><span class="p">(</span><span class="n">file_path</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">circuit</span><span class="o">.</span><span class="n">script_dir</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">file_path</span> <span class="o">+</span> <span class="s2">&quot;:&quot;</span> <span class="o">+</span> <span class="n">file_line</span></div>
</div>


</pre></div>

            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SKiDL 2.2.0 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">skidl.skidlbaseobj</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
    &#169; Copyright 2016-2025, Dave Vandenbout.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
    </div>
  </body>
</html>